﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using DXApplicationTangche.UC.货号管理.service;
using DevExpress.XtraEditors.Popup;
using DevExpress.Utils.Win;
using DevExpress.XtraGrid.Editors;
using DevExpress.XtraLayout;
using DXApplicationTangche.UC.款式管理.service;

namespace DXApplicationTangche.UC.货号管理.销售款式
{
    public partial class Form销售款式维护 : DevExpress.XtraEditors.XtraForm
    {
        public Form销售款式维护()
        {
            InitializeComponent();
        }
        
        private void simpleButton确认_Click_1(object sender, EventArgs e)
        {
            if (String.IsNullOrEmpty(this.textBox成衣条码.Text.Trim()) 
                || String.IsNullOrEmpty(this.comboBox款式标签.Text.Trim())
                || String.IsNullOrEmpty(this.comboBox性别标签.Text.Trim())
                || String.IsNullOrEmpty(this.textBox单价.Text.Trim()))
            {
                MessageBox.Show("请将信息填写完整");
                return;
            }
            try
            {
                DTO销售款式 DTO销售款式 =
                    货号管理Service.createInvetoryByBarcode(
                        this.textBox成衣条码.Text.Trim(),
                        this.comboBox款式标签.Text.Trim(),
                        this.comboBox性别标签.Text.Trim(),
                        Convert.ToDouble(this.textBox单价.Text.Trim())
                        );
                new Form销售款式维护确认(DTO销售款式).ShowDialog();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
            this.Close();
        }

        private void textBox单价_KeyPress(object sender, KeyPressEventArgs e)
        {
            //允许输入数字、小数点、删除键和负号  
            if ((e.KeyChar < 48 || e.KeyChar > 57) && e.KeyChar != 8 && e.KeyChar != (char)('.'))
            {
                //MessageBox.Show("请输入正确的数字");
                this.textBox单价.Text = "";
                e.Handled = true;
            }
            if (e.KeyChar == (char)('-'))
            {
                if (textBox单价.Text != "")
                {
                    //MessageBox.Show("请输入正确的数字");
                    this.textBox单价.Text = "";
                    e.Handled = true;
                }
            }
            //小数点只能输入一次  
            if (e.KeyChar == (char)('.') && ((TextBox)sender).Text.IndexOf('.') != -1)
            {
                //MessageBox.Show("请输入正确的数字");
                this.textBox单价.Text = "";
                e.Handled = true;
            }
            //第一位不能为小数点  
            if (e.KeyChar == (char)('.') && ((TextBox)sender).Text == "")
            {
                //MessageBox.Show("请输入正确的数字");
                this.textBox单价.Text = "";
                e.Handled = true;
            }
            //第一位是0，第二位必须为小数点  
            if (e.KeyChar != (char)('.') && ((TextBox)sender).Text == "0")
            {
                //MessageBox.Show("请输入正确的数字");
                this.textBox单价.Text = "";
                e.Handled = true;
            }
            //第一位是负号，第二位不能为小数点  
            if (((TextBox)sender).Text == "-" && e.KeyChar == (char)('.'))
            {
                //MessageBox.Show("请输入正确的数字");
                this.textBox单价.Text = "";
                e.Handled = true;
            }
        }
    }
}